package zhan;

/**
 * @Author: Hasee
 * @Date: 2020-12-03 11:04:33
 */
public class BracketsMatch {
    public static void main(String[] args) {
        String s="((1)221(3)45(4(32)5(34)32(45)463(4)35)4)))464";
        boolean match=isMatch(s);
        System.out.println(match);
    }

    private static boolean isMatch(String s) {
        //创建栈用于保存左括号
        Stack<String> chars=new Stack<String>();
        //遍历字符串

        for (int i=0;i<s.length();i++){
            String currChar=s.charAt(i)+"";
            if (currChar.equals("(")){
                chars.push(currChar);
            }else if (currChar.equals(")")){
                String t=chars.pop();
                if (t==null){
                    return false;
                }
            }
        }
        if (chars.isEmpty()){
            return true;
        }
        return false;
    }
}
